package com.four.seckill.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.four.seckill.entity.Seckill;
import com.four.seckill.feign.ShopFeignService;
import com.four.seckill.mq.Purducre;
import com.four.seckill.service.ISeckillService;
import com.four.seckill.vo.SeckillVo;
import com.four.seckill.vo.SeckillVo2;
import com.guli.common.utils.R;
import com.guli.common.vo.ManageVo;
import com.guli.common.vo.ParameterVo;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gs
 * @since 2021-12-22
 */
@RestController
@RequestMapping("/seckill")
public class SeckillController {

    @Autowired
    private ISeckillService seckillService;

    @Autowired
    private Purducre purducre;

    @Autowired
    private ShopFeignService service;
    @PostMapping("/ManageList")
    public R bargainList(
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "pageSize",defaultValue = "3")Integer pageSize,
            @RequestBody ManageVo vo){

        return  service.bargainList(page,pageSize,vo);
    }
    /**
     * 根据根据选择的id获取改商品信息
     * @param manId
     * @return
     */
    @GetMapping("/findManageById/{manId}")
    public R findManageById(@PathVariable("manId")Integer manId){
        ManageVo manageVo=service.getManageById(manId);
        return R.ok().put("manageVo",manageVo);
    }

    /**
     * 根据商品id查询商品属性
     * @param manId
     * @return
     */
    @GetMapping("/findParameterById/{manId}")
    public R findParameterById(@PathVariable("manId")Integer manId){
        List<ParameterVo>parameterVo=service.findParameterById(manId);
        return R.ok().put("parameterVo",parameterVo);
    }

    /**
     * 添加
     * @param vo
     * @return
     */
    @PostMapping("save")
    public R save(@RequestBody SeckillVo vo){
        seckillService.addVo(vo);


        return R.ok();
    }
    /**
     *
     */
    @GetMapping("/getById/{id}")
    public R getById(@PathVariable("id") Integer id){

        Seckill seckill = seckillService.getByIds(id);

        return R.ok().put("list",seckill);
    }

    @PutMapping("updateApp")
    public R updateApp(@RequestBody Seckill seckill){
        seckillService.updateApp(seckill);

        return R.ok();
    }

    @PostMapping("/findAll")
    public R findAll(
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "pageSize",defaultValue = "3")Integer pageSize
    ){
        IPage<SeckillVo2> pages = seckillService.findAll(page,pageSize);

        return R.ok().put("list",pages);
    }


    /**
     * 用户秒杀
     */

    @PutMapping("/userseckillgoods")
    public void userseckillgoods(
            @RequestParam("seId")Integer seid,
            @RequestParam("userName") String userName
    ){
        purducre.userseckillgoods(seid,userName);
    }
}
